package com.id.supaclean.ktx

import android.animation.Animator
import com.airbnb.lottie.LottieAnimationView

fun LottieAnimationView.addAnimatorListener(
    onCancel: ((Animator) -> Unit)? = null,
    onRepeat: ((Animator) -> Unit)? = null,
    onStart: ((Animator) -> Unit)? = null,
    onEnd: ((Animator) -> Unit)? = null,
) {
    addAnimatorListener(object : Animator.AnimatorListener {
        override fun onAnimationStart(animator: Animator) {
            onStart?.invoke(animator)
        }

        override fun onAnimationEnd(animator: Animator) {
            onEnd?.invoke(animator)
        }

        override fun onAnimationCancel(animator: Animator) {
            onCancel?.invoke(animator)
        }

        override fun onAnimationRepeat(animator: Animator) {
            onRepeat?.invoke(animator)
        }
    })
}